package com.spdzen.controller.admin;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.spdzen.service.WechatConfigService;
import com.spdzen.support.AdminLoginUtils;
import com.spdzen.support.LogUtils;
import com.spdzen.support.result.JsonResult;
import com.spdzen.vo.WechatConfigVO;

@Controller
@RequestMapping("/admin/wechat/config")
public class WechatConfigAdminController {
	@Resource
	private WechatConfigService wechatConfigService;

	@RequestMapping("/view.do")
	public String pageView() {
		return "/admin/wechat/configView";
	}
	
	@RequestMapping("/detail.do")
	@ResponseBody
	public JsonResult detail() {
		try {			
			return JsonResult.success(wechatConfigService.selectWechatConfig());
		} catch (Exception e) {
			LogUtils.logError(e);
			return JsonResult.error();
		}
	}
	
	@RequestMapping("/update.do")
	@ResponseBody
	public JsonResult update(WechatConfigVO vo, HttpServletRequest request) {
		try {
			wechatConfigService.updateWechatConfig(vo, AdminLoginUtils.getUserId());
			return JsonResult.success();
		} catch (Exception e) {
			LogUtils.logError(e, vo);
			return JsonResult.error();
		}
	}
	
	@RequestMapping("/reset.do")
	@ResponseBody
	public JsonResult reset(HttpServletRequest request) {
		try {
			wechatConfigService.updateWechatConfig(new WechatConfigVO(), AdminLoginUtils.getUserId());
			return JsonResult.success();
		} catch (Exception e) {
			LogUtils.logError(e);
			return JsonResult.error();
		}
	}
}
